/*******************************************************************************
*
*   Copyright(c), 2010 ~ 2020 .
*
********************************************************************************   
*   File Name   : catch_def.h
*   Version     : 
*   Author      : chenglaifu 
*   Date        : 2011-08-04
*   Description : 
*
*   Histiory    :
*               :
*               :
*******************************************************************************/
#ifndef __CATCH_DEF_H__
#define __CATCH_DEF_H__

#include <assert.h>
#include "typedef.h"

#ifdef __cplusplus
extern "C"{
#endif

#define CATCH_SUCCESS  ((unsigned int)0UL)
#define CATCH_FAILURE  ((unsigned int)1UL)
#define CATCH_ERROR_CODE_INCOMPLETE (0xFFFFFFFFUL)
#define CATCH_ERROR_CODE_INIT (0xFFFFFFCCUL)

#define CATCH_ERROR_CODE()      (__catch_error_code)
#define CATCH_ERROR_LINE_NO()   (__catch_error_line_no)

#define CATCH_ASSERT()          {assert(0);}

#define CATCH_ERROR_PROC()      {__catch_error_line_no = (EOS_UINT32)__LINE__;/* LOG */}

#define THROW(errcode)          {__catch_error_code = errcode;  CATCH_ERROR_PROC(); \
                                goto __tagErrorcode;}

#define CATCH_PROC              {unsigned int __catch_error_code = CATCH_ERROR_CODE_INIT;\
                                 unsigned int  __catch_error_line_no = 0xFFFFFFFFUL;

#define END_PROC    THROW(CATCH_ERROR_CODE_INCOMPLETE);\
__tagErrorcode:

#define CATCH_ERROR(errcode)    {if(errcode == __catch_error_code){
#define CACTH_ALL_ERROR         {
#define END_CATCH_ERROR         }}

#define EXEC(func)              {__catch_error_code = (func); \
                                if(CATCH_SUCCESS != __catch_error_code){THROW(__catch_error_code);}}
#define EXEC_EX(errcode, func)  {if(CATCH_SUCCESS != (func)){THROW(errcode);}}
#define EXEC_ASSERT(func)       {__catch_error_code = (func); \
                                if(CATCH_SUCCESS != __catch_error_code){CATCH_ASSERT();THROW(__catch_error_code);}}

#define JUDGE(expr)             {if(CATCH_SUCCESS != (expr)){THROW(CATCH_FAILURE);}}
#define JUDGE_EX(errcode,expr)  {if(CATCH_SUCCESS != (expr)){THROW(errcode);}}
#define JUDGE_ASSERT(expr)      {if(CATCH_SUCCESS != (expr)){CATCH_ASSERT();THROW(CATCH_FAILURE);}}


#define DEBUG   printf
#define CHECK ((condition),(MSG),(RET))\
    if(condition)\
    {\
        DEBUG(MSG);\
        return (RET);\
    }\

#ifdef __cplusplus
}
#endif 

#endif      /* __CATCH_DEF_H__ */

